import { Controller } from 'egg';

export default class DjController extends Controller {
    public async index() {
        const { ctx } = this;
        ctx.body = await ctx.service.test.sayHi('egg');
    }


    // 推荐电台
    public async recommend() {
        const url = `/weapi/djradio/recommend/v1`;
        let result = await this.service.mequest.createWebAPIRequest(url, 'POST', {})
        this.ctx.body = result.body;
    }
    // 电台分类
    public async catelist(){
        const url =  `/weapi/djradio/category/get`;
        let result = await this.service.mequest.createWebAPIRequest(url, 'POST', {})
        this.ctx.body = result.body;
    }
    // 分类推荐
    public async recommendByType(){
        const data = {cateId:this.ctx.query.type};
        const url =     `/weapi/djradio/recommend`;
        let result = await this.service.mequest.createWebAPIRequest(url, 'POST', data)
        this.ctx.body = result.body;
    }

    // 订阅
    public async sub(){
        const {id,t}=this.ctx.query;
        const data = {id}
        const action = t==1?'sub':'unsub';
        const url = `/weapi/djradio/${action}`;
        let result = await this.service.mequest.createWebAPIRequest(url, 'POST', data)
        this.ctx.body = result.body;
    }
    //订阅列表
    public async sublist (){
        const {offset,limit}=this.ctx.query;
        const data = {offset,limit};
        const url = `/weapi/djradio/get/subed`;
        let result = await this.service.mequest.createWebAPIRequest(url, 'POST', data)
        this.ctx.body = result.body;
    }
    // 电台详情
    public async detail (){
        const data ={id:this.ctx.query.id};
        const url =  "/weapi/djradio/get";
        let result = await this.service.mequest.createWebAPIRequest(url, 'POST', data)
        this.ctx.body = result.body;
    }
    // 电台节目
    public async program (){
        const {id,offset,limit,}=this.ctx.query;
        const data = {
            radioId: id,
            limit: limit || 30,
            offset: offset || 0,
        }
        const url = "/weapi/dj/program/byradio";
        let result = await this.service.mequest.createWebAPIRequest(url, 'POST', data)
        this.ctx.body = result.body;
    }

}
